#include <CoreMIDI/MIDIServices.h>
#include <CoreServices/CoreServices.h>
#include <CoreFoundation/CoreFoundation.h>

#include <stdio.h>

void myReadProc(const MIDIPacketList *pktlist, void *readProcRefCon, void *srcConnRefCon); 

int main()
{
  printf ("Hello World!\n");
  
  OSStatus stat;
  MIDIClientRef client;
  MIDIPortRef inPort;
  MIDIPortRef outPort;

  MIDIEndpointRef src; 

  int num;

  stat = MIDIClientCreate(CFSTR("Midi device"), NULL, NULL, &client);
  printf("status client: %d [%d]\n", stat, client);
  stat = MIDIInputPortCreate(client, CFSTR("input"), NULL, NULL, &inPort);
  printf("status input: %d\n", stat);
  stat = MIDIOutputPortCreate(client, CFSTR("output"), &outPort); 
  printf("status output: %d\n", stat);
  
  //stat = MIDIDestinationCreate(client, CFSTR("virtual dst"), myReadProc, NULL, &src);
  stat = MIDISourceCreate(client, CFSTR("virt midi"), &src);
  printf("status virt src: %d\n", stat);

  num = MIDIGetNumberOfSources();
  printf("num sources: %d\n", num);

  //src = MIDIGetSource(1);
  //printf("src: %s\n", src);
  stat = MIDIPortConnectSource(inPort, src, NULL);
  printf("status conn: %d\n", stat);


  num = MIDIGetNumberOfDestinations();
  printf("num dst: %d\n", num);

  for(;;)
      { 
	//printf ("Hello World!\n");
	}
  return 0;
} 
